<!--
 * @Author: 胡海
 * @Date: 2020-11-22 16:09:57
 * @LastEditors: 胡海
 * @LastEditTime: 2020-11-22 16:12:16
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Object.defineProperty</title>
    <script src="../vue/src/vue.js"></script>
</head>
<body>
    <div id="app">
        <button id="btn">改变数据</button>
        <h2 id="title">这是标题</h2>
    </div>

    <script>
        var data = {
            title: '新闻'
        }
        var val = '新的值'
        Object.defineProperty(data,'title', {
            get(){
                console.log('我访问数据了');
                return val
            },
            set(newValue){
                console.log('我设置了新值');
                console.log(newValue);
                val = newValue;
            }
        })

        console.log( data.title );

        data.title = '123';

        console.log(data.title);



    </script>
</body>
</html>